# 1.导包 加载模块
from openpyxl import load_workbook, Workbook

# 2.加载 路径下面的 excel文件
from openpyxl.cell import Cell

wb = load_workbook('05-read_cell_data.xlsx')

# 3.获取表
sheet = wb.worksheets[0]
print(sheet.title)

# 4.获取单元格 --取值
cell:Cell = sheet['C2']
# print('单元格的数据:', cell.value)

###########################安行获取数据########################
# row = sheet[2]
# for cell in row:
#     print(cell.value)

############################按列获取数据########################
# col = sheet['A']
# for cell in col:
#     print(cell.value)

# 添加 注解 批注 ----为了测试 获取批注
# new_wb = Workbook()
#
# new_ws = new_wb.active
#
# new_ws['A1'] = '获取注解'
# from openpyxl.comments import Comment
# new_ws['A1'].comment= Comment('新数据演示com', 'LCF')
#
# new_wb.save('05-read_cell_data.xlsx')

# print('获取批注:', sheet['A1'].comment)
# print('获取批注:', sheet['A1'].comment.content)
# print('获取批注:', sheet['A1'].comment.author)

############################读取属性########################

style_wb = load_workbook('03celluse.xlsx')
sheet = style_wb.worksheets[0]

cell:Cell = sheet['C5']
# 字体
# print('字体:', cell.font.name)
# 字体大小
# print('字体大小:', cell.font.size)
# 字体颜色
# print('字体颜色:', cell.font.color)


# print(cell.font.bold) # 是否加粗
# print(cell.font.underline) # 有无下划线
# print(cell.font.italic) # 是否斜体
# print(cell.font.strike) # 有无删除线

row = cell.row
col = cell.column
# print('当前值的所在行是第{}行'.format(row))
# print('当前值的所在列是第{}列'.format(col))


# 根据列号  取出 列名字
from openpyxl.utils import get_column_letter
col_name = get_column_letter(col)
print('列名:', col_name)

# 根据列名字 取出  列号
from openpyxl.utils import column_index_from_string
col_index = column_index_from_string(col_name)
print('列号:', col_index)


# print(cell.alignment.wrap_text) # 是否自动换行
# print(cell.alignment.horizontal) # 垂直对齐方式
# print(cell.alignment.vertical) # 水平对齐方式​
# print(cell.fill.fgColor) # 单元格背景颜色


# 单元格边线的样式和颜色
print(cell.border.left.style)
print(cell.border.left.color)
print(cell.border.right.color)
print(cell.border.top.color)
print(cell.border.bottom.color)